package com.coc.controller;

import com.coc.service.RabbitProducer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
@RequestMapping("/mq")
@Api(tags = "Rabbit - 测试接口")
public class RabbitMqTestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private RabbitProducer producer;


    @RequestMapping(value = "/rabbit", method = RequestMethod.GET)
    @ApiOperation(value = "Rabbit [普通模式] 测试接口",  notes = "演示Rabbit 普通模式", tags = "1.0.0", nickname = "alaxi")
    public Object sayHello ( @ApiParam(name = "message", value = "消息", required = true) @RequestParam("message") String message) {
        producer.putMessage(message);
        return "hello " + message ;
    }

    @RequestMapping(value = "/fanout", method = RequestMethod.GET)
    @ApiOperation(value = "Rabbit [广播模式] 测试接口",  notes = "演示Rabbit 广播模式", tags = "1.0.0", nickname = "kawayi")
    public Object sayFanout ( @ApiParam(name = "message", value = "消息", required = true) @RequestParam("message") String message) {
        producer.putFanoutMessage(message);
        return "hello " + message ;
    }


    @RequestMapping(value = "/topic", method = RequestMethod.GET)
    @ApiOperation(value = "Rabbit [Topic] 测试接口",  notes = "演示Rabbit Topic模式", tags = "1.0.0", nickname = "sikuoyi")
    public Object sayTopic ( @ApiParam(name = "message", value = "消息", required = true) @RequestParam("message") String message) {
        producer.putTopicA(message);
        producer.putTopicB(message);
        producer.putTopicC(message);
        return "hello " + message ;
    }


}
